package com.ruoyi.web.controller.bussiness;


import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.QRCodeUtil;
import com.ruoyi.common.utils.file.FileUploadUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;

@RestController
@RequestMapping("/sys/qrCode")
public class QrCodeController extends BaseController {

    /**
     * 生成二维码并返回访问链接
     *
     * @param content 二维码内容
     * @return 二维码图片的访问链接
     */
    @PostMapping("/generate")
    public AjaxResult generateQrCode(@RequestParam String content) {
        try {
            content="测试二维码内容";
            String filePath="D:\\project\\药品说明\\1.jpg";
            String  format ="JPEG";
            // 生成二维码图片
            BufferedImage bufferedImage = QRCodeUtil.createImage("UTF-8", content, 400, 400);

            File outputFile = new File(filePath);
            ImageIO.write(bufferedImage, format, outputFile);
            System.out.println("图像保存成功！");

            // 返回二维码图片的访问链接
           // String qrCodeUrl = RuoYiConstant.RESOURCE_PREFIX + fileName;
            String qrCodeUrl ="";
            return AjaxResult.success(qrCodeUrl);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("二维码生成失败，请联系管理员");
        }
    }

}
